<?php
class App_Rights
{
    protected $_acl;

    protected $_roleName;

    public function __construct()
    {    
    	
        $this->_acl = new Zend_Acl();

        $this->_acl->addRole(new Zend_Acl_Role('Guest')) 
        		   ->addRole(new Zend_Acl_Role('User'), 'Guest')                    
                   ->addRole(new Zend_Acl_Role('Admin'), 'User');

        $this->_acl->add(new Zend_Acl_Resource('index'))   
        		   ->add(new Zend_Acl_Resource('stock'))            
                   ->add(new Zend_Acl_Resource('user'))
                   ->add(new Zend_Acl_Resource('log'))
                   ->add(new Zend_Acl_Resource('auth'))
                   ->add(new Zend_Acl_Resource('office'))
        			->add(new Zend_Acl_Resource('statistics'));
                   
        $this->_acl->allow('User', 'user', array('login','logout','changepsw','image'));
        $this->_acl->allow('User', 'auth', array('add','index','update','delete'));
        $this->_acl->allow('User', 'stock', array(
        		'index','add','update','updatestockvalue','addnum',
        		'unusual','specialmanage','delete','exportcurstock',
        		'exportlowstock','exportoutstock','printlow',
        		'printout','printbaohuo','print','createword','barcode',
        		'image','word','minustock','addstock',
        		'exportstock','deladd','inventory','submitinventory','updateinventory'));
        $this->_acl->allow('User', 'index', array('index','skin'));
        $this->_acl->allow('User', 'log', array(
        		'index','omodify','domodify','modifylog','omemo','scanimport',
        		'scanout','scanexport','numlog','order','returnorder',
        		'export','special','imloadstock','exloadstock','modifyadd','alloutstock',
        		'scansort','opersort','deletesort','pack','oper',
        		'sortlog','operlog','packlog','makelist','printlist','createlist',
        		'baohuo','deletebh','loadsku','dailybaohuo'));
        $this->_acl->allow('Guest', 'statistics', array('eday','eweek','emonth','equarter','eyear'));
        $this->_acl->allow('Guest', 'office', array('loaduser','pubneed','pubdaily','myneed','mytask','mydaily','tasks','needs','dailys','begin','finish','updateneed','viewqaitem','updatedaily','deleteqaitem','evaluate','memo'));
        $this->_acl->allow('Guest', 'user', array('login','logout','image'))      		       
                   ->allow('Admin');                
    }

    public function isAllowed($roleName, $resourceName, $actionName)
    {
        if ($this->_acl->isAllowed($roleName, $resourceName, $actionName)) {
            return true;
        } else {
            return false;
        }
    }
}